<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Home</title>
<link href="assets/css/lib/themify-icons.css" rel="stylesheet">
<link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
<link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/style.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet" />
<script src="js/jquery.min.js"></script>
<script src="js/layer-v3.1.1/layer/layer.js"></script>
<script src="js/demo.js"></script>
<script type="text/javascript" src="js/pagination.js"></script>
</head>
<%
	String key = request.getParameter("keywords");
%>
<script type="text/javascript">
var bookdelete = function (){
	var bookid=$("#bookid").val();
	alert(ID);
	$.ajax({
		type: 'POST',
		url: '<%=request.getContextPath() %>/bookdelete?bookid="'+bookid+'"',
		dataType: 'json',
		data: {},
		contentType: 'application/json;charset=UTF-8',
		success: function(e) {
			if (e.status === "COMMITTED") {
			}
			window.location="<%=request.getContextPath() %>/manage/bookmanager.jsp?keywords=<%=key%>";
		},
	error: function(XMLHttpRequest, textStatus, errorThrown) {
    },
	});
}
function AddBook(){
    layer.open({
        type:1,
        title:"添加商品",
        area:["395px","600px"],
        shade: 0.6 //遮罩透明度
        ,maxmin: true //允许全屏最小化
        ,anim: 1 //0-6的动画形式，-1不开启
        ,
        content:$("#loginBox2"),
        cancel: function(index, layero){ 
        	  if(confirm('确定要关闭么')){ //只有当点击confirm框的确定时，该层才会关闭
        	    layer.close(index);
        	    $("#loginBox2").css("display","none");
        	  }
        	  return false; 
        	} ,
        });
}
var commoditymodify = function (){
	var bookid=$.trim($("#InputBookid").val());
    var title=$.trim($("#InputTitle").val());
    var author=$.trim($("#InputAuthor").val());
    var publisher=$.trim($("#InputPublisher").val());
    var publishingtime=$.trim($("#InputPublishingTime").val());
    var bookprice=$.trim($("#InputBookPrice").val());
    var categoryid=$.trim($("#InputCategoryId").val());
    var inventory=$.trim($("#InputInventory").val());
    var description=$.trim($("#InputDescription").val());
	$.ajax({
		type: 'POST',
		url: '<%=request.getContextPath()%>/BookModify',
		dataType: 'json',
		data: JSON.stringify({
			bookid: bookid,
			title: title,
			author: author,
			publisher: publisher,
			publishingtime: publishingtime,
			bookprice: bookprice,
			categoryid: categoryid,
			inventory: inventory,
			description: description
		}),
		contentType: 'application/json;charset=UTF-8',
		success: function(e) {
			if (e.status === "COMMITTED") {
				window.alert('已提交执行');
			}
			window.location="<%=request.getContextPath()%>/manage/bookmanager.jsp?keywords=<%=key%>";
		},
	error: function(XMLHttpRequest, textStatus, errorThrown) {
		 $("#loginBox").css("display","none");
    },
	});
}
var bookAdd = function (){
    var title=$.trim($("#InputTitle2").val());
    var author=$.trim($("#InputAuthor2").val());
    var publisher=$.trim($("#InputPublisher2").val());
    var publishingtime=$.trim($("#InputPublishingTime2").val());
    var bookprice=$.trim($("#InputBookPrice2").val());
    var categoryid=$.trim($("#InputCategoryId2").val());
    var inventory=$.trim($("#InputInventory2").val());
    var description=$.trim($("#InputDescription2").val());
	$.ajax({
		type: 'POST',
		url: '<%=request.getContextPath()%>/BookAdd',
		dataType: 'json',
		data: JSON.stringify({
			title: title,
			author: author,
			publisher: publisher,
			publishingtime: publishingtime,
			bookprice: bookprice,
			categoryid: categoryid,
			inventory: inventory,
			description: description
		}),
		contentType: 'application/json;charset=UTF-8',
		success: function(e) {
			if (e.status === "COMMITTED") {
				window.alert('已提交执行');
			}
			window.location="<%=request.getContextPath()%>/manage/bookmanager.jsp?keywords=<%=key%>";
		},
	error: function(XMLHttpRequest, textStatus, errorThrown) {
		 $("#loginBox2").css("display","none");
    },
	});
}
</script>
<style>
.black_overlay {
	display: none;
	position: absolute;
	top: 0%;
	left: 0%;
	width: 100%;
	height: 100%;
	background-color: white;
	z-index: 1001;
	-moz-opacity: 0.8;
	opacity: .30;
	filter: alpha(opacity = 88);
}

.white_content {
	display: none;
	position: absolute;
	top: 25%;
	left: 25%;
	width: 55%;
	height: 55%;
	padding: 20px;
	border: 5px solid aliceblue;
	background-color: white;
	z-index: 1002;
	overflow: auto;
}

#loginBox2 {
	display: none;
}
</style>
<script type="text/javascript" src="../js/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    	 window.onload=function(){
        	 xmlhttp = new XMLHttpRequest();
        	 xmlhttp.onreadystatechange = function(){
        			if(xmlhttp.readyState==4) {
        		  	    if(xmlhttp.status==200) {
        				      var respTxt = xmlhttp.responseText;
        				      window.eval("var arr="+respTxt);
        				      var html='<div class="card-body"><div class="table-responsive">';
        				      html+='<table class="table student-data-table m-t-20"><thead>';
        				      html+='<tr><th>id</th><th>title</th><th>author</th><th>publisher</th><th>publishing_time</th><th>price</th><th>inventory</th><th>edit</th><th>delete</th></tr>';
        				      for(var i=0;i<arr.length;i++){
        				          html += '<tbody id="tablelsw"><tr><td>'+arr[i].book_id+'</td>';
        				          html += '<td>'+arr[i].title+'</td>';
        				          html += '<td>'+arr[i].author+'</td>';
        				          html += '<td>'+arr[i].publisher+'</td>';
        				          html += '<td>'+arr[i].publishing_time+'</td>';
        				          html += '<td>'+arr[i].book_price+'</td>';
        				          html += '<td>'+arr[i].inventory+'</td>';
        				          html += '<td><a href="javascript:;" onclick="ShowCommodityText(\''+arr[i].book_id+'\',\''+arr[i].title+'\',\''+arr[i].author+'\',\''+arr[i].publisher+'\',\''+arr[i].publishing_time+'\',\''+arr[i].book_price+'\',\''+arr[i].category_id+'\',\''+arr[i].inventory+'\',\''+arr[i].description+'\')">编辑</a></td>';
        				          html += '<td><a href="">删除</a></td></tr>';
        				          
        				      }
        				      html+='</table></div></div>';
        				      
        				      document.getElementById("c").innerHTML=html;
        			    }
        		     }
        	 }
        	 xmlhttp.open("get","../ShowAllBooks?keywords="+"<%=key%>");
        	 xmlhttp.send(null); 
         }
</script>
<script type="text/javascript">
    function jumpSearch(){
    	var keywords=$("#keywords").val();
        window.location.href="../manage/bookmanager.jsp?keywords="+keywords;
    }
</script>

<body>
	<div
		class="sidebar sidebar-hide-to-small sidebar-shrink sidebar-gestures">
		<div class="nano">
			<div class="nano-content">
				<ul>
					<div class="logo">
						<a href="index.jsp"><span>管理员后台系统</span></a>
					</div>
					<li class="label">Main</li>
					<li><a class="sidebar-sub-toggle"><i class="ti-home"></i>用户管理
							<span class="sidebar-collapse-icon ti-angle-down"></span></a>
						<ul>
							<li><a href="allUser.jsp">查看所有用户</a></li>
						</ul></li>
					<li><a class="sidebar-sub-toggle"><i
							class="ti-bar-chart-alt"></i>商品管理 <span
							class="sidebar-collapse-icon ti-angle-down"></span></a>
						<ul>
							<li><a href="bookmanager.jsp">商品信息修改</a></li>
						</ul></li>
<li><a class="sidebar-sub-toggle"><i class="ti-bar-chart-alt"></i>订单管理 <span class="sidebar-collapse-icon ti-angle-down"></span></a>
                            <ul>
                                <li><a href="order.jsp">订单信息修改</a></li>
                            </ul>
                        </li>
				</ul>
			</div>
		</div>
	</div>
	<div class="header">
		<div class="container-fluid">
			<div class="row">
				<div class="col-lg-12">
					<div class="dropdown dib">
						<div class="header-icon" data-toggle="dropdown">
							<span class="user-avatar"><%=request.getSession().getAttribute("userid") %> <i
								class="ti-angle-down f-s-10"></i>
							</span>
							<div
								class="drop-down dropdown-profile dropdown-menu dropdown-menu-right">
								<div class="dropdown-content-body">
									<ul>
										<li><a href="#"> <i class="ti-settings"></i> <span>Setting</span>
										</a></li>

										<li>
                                                <a onclick='location="<%=request.getContextPath() %>/exit"'>
                                                    <i class="ti-power-off"></i>
                                                    <span>Logout</span>
                                                </a>
                                            </li>
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</div>

	<div class="content-wrap">
		<div class="main">
			<div class="container-fluid">
				<div class="row">
					<div class="col-lg-8 p-r-0 title-margin-right">
						<div class="page-header">
							<div class="page-title">
								<h1>
									Hello, <span>There are all commodities.</span>
								</h1>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div>
				<div class="card">
					<div class="card-title pr">
						<h4>All Exam Result</h4>
					</div>
					<div>
						<input type="text" placeholder="请输入关键字" name="keywords"
							id="keywords">
						<button id="btn" type="submit" onclick=jumpSearch()>搜索</button>
						<button type="button" onClick="AddBook()">添加商品</button>
					</div>
					<div id='c'></div>
				</div>
			</div>
		</div>
	</div>
	<div id="loginBox">
		<div class="login-item">
			<input type="text" id="InputBookid" placeholder="id" />
		</div>
		<div class="login-item">
			<input type="text" id="InputTitle" placeholder="title" />
		</div>
		<div class="login-item">
			<input type="text" id="InputAuthor" placeholder="author" />
		</div>
		<div class="login-item">
			<input type="text" id="InputPublisher" placeholder="publisher" />
		</div>
		<div class="login-item">
			<input type="text" id="InputPublishingTime"
				placeholder="publishingTime" />
		</div>
		<div class="login-item">
			<input type="text" id="InputBookPrice" placeholder="passwd" />
		</div>
		<div class="login-item">
			<input type="text" id="InputCategoryId" placeholder="categrory" />
		</div>
		<div class="login-item">
			<input type="text" id="InputInventory" placeholder="inventory" />
		</div>
		<div class="login-item">
			<input type="text" id="InputDescription" placeholder="description" />
		</div>
		<div class="login-item">
			<a href="javascript:;" onclick="commoditymodify()">修改</a>
		</div>
	</div>
	<div id="loginBox2">
		<div class="login-item">
			<input type="text" id="InputTitle2" placeholder="title" />
		</div>
		<div class="login-item">
			<input type="text" id="InputAuthor2" placeholder="author" />
		</div>
		<div class="login-item">
			<input type="text" id="InputPublisher2" placeholder="publisher" />
		</div>
		<div class="login-item">
			<input type="text" id="InputPublishingTime2"
				placeholder="publishingTime" />
		</div>
		<div class="login-item">
			<input type="text" id="InputBookPrice2" placeholder="bookprice" />
		</div>
		<div class="login-item">
			<input type="text" id="InputCategoryId2" placeholder="categrory" />
		</div>
		<div class="login-item">
			<input type="text" id="InputInventory2" placeholder="inventory" />
		</div>
		<div class="login-item">
			<input type="text" id="InputDescription2" placeholder="description" />
		</div>
		<div class="login-item">
			<a href="javascript:;" onclick="bookAdd()">添加</a>
		</div>
		<div id="deleteBox">
		<p>确定要删除该用户吗？</p>
		<div class="login-item"><input type="hidden" id="bookid" /></div>
    	<div class="delete-item div-inline"><a href="javascript:;" onclick="bookdelete()">确认</a></div>
    	<div class="delete-item div-inline"><a href="javascript:;" onclick="cancel()">取消</a></div>
		</div>
	</div>
	<script src="assets/js/lib/jquery.min.js"></script>
	<script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
	<script src="assets/js/lib/menubar/sidebar.js"></script>
	<script src="assets/js/lib/preloader/pace.min.js"></script>
	<script src="assets/js/lib/bootstrap.min.js"></script>
	<script src="assets/js/lib/circle-progress/circle-progress.min.js"></script>
	<script src="assets/js/lib/circle-progress/circle-progress-init.js"></script>
</body>

</html>